package com.csu.tingtian.controller;

import com.csu.tingtian.common.CommonResponse;
import com.csu.tingtian.service.MessageService;
import com.csu.tingtian.vo.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/message/")
public class MessageController {
    @Autowired
    private MessageService messageService;
    //    用户向商家发送消息
    @PostMapping("messages/{username}/{farmname}/{usercontent}/{usercontenttime}")
    CommonResponse<Message> userSendMessageToFarm(@PathVariable("username") String userName,
                                                  @PathVariable("farmname") String farmName,
                                                  @PathVariable("usercontent") String userContent){
        return messageService.userSendMessageToFarm(userName, farmName, userContent);
    }
    //    商家向用户发送消息
    @PostMapping("messages/{farmname}/{username}/{farmcontent}/{farmcontenttime}")
    CommonResponse<Message> farmSendMessageTouser(@PathVariable("farmname") String farmName,
                                                  @PathVariable("username") String userName,
                                                  @PathVariable("farmcontent") String farmContent){
        return messageService.farmSendMessageTouser(farmName, userName, farmContent);
    }
    //    查看聊天记录
    @GetMapping("messages/{username}/{farmname}")
    CommonResponse<List<Message>> getMessage(@PathVariable("username") String userName,
                                             @PathVariable("farmname") String farmName){
        return messageService.getMessage(userName, farmName);
    }
    //    用户删除自己和某商家的聊天记录
    @DeleteMapping("username/{username}/farmname/{farmname}")
    CommonResponse<Message> deleteMessage(@PathVariable("username") String userName,
                                          @PathVariable("farmname") String farmName){
        return messageService.deleteMessage(userName, farmName);
    }
}
